import request from '../utils/request'
//前台
//获取商铺列表
export const getShopList = () => {
    return request({
        url: '/shop/list',
        method: 'get'
    })
}

//获取商铺详情
export const getShopDetail = (id) => {
    return request({
        url: `/shop/detail/${id}`,
        method: 'get',
        params: {
            shopId: id
        }
    })
}

//获取商铺卡片
export const getShopCard = (id) => {
    return request({
        url: `/shop/card`,
        method: 'get',
        params: {
            id
        }
    })
}

//是否入驻
export const isShop = () => {
    return request({
        url: `/shop/hasShop`,
        method: 'get'
    })
}



//后台

//获取商铺列表
export const getAllShopList = (page = 1, size = 10) => {
    return request({
        url: '/shop/jiang/list',
        method: 'get',
        params: { page, size }
    })
}

export const addShop = (shop) => {
    return request({
        url: `/shop/jiang/add`,
        method: 'post',
        data: shop
    })
}
export const updateShop = (shop) => {
    // 确保shop对象中包含id
    if (!shop.id) {
        console.error('更新店铺时缺少id字段')
        return Promise.reject(new Error('更新店铺时缺少id字段'))
    }
    
    return request({
        url: `/shop/jiang/update`,
        method: 'post',
        data: shop
    })
}
export const deleteShop = (id) => {
    return request({
        url: `/shop/jiang/delete/${id}`,
        method: 'post',
        params: {
            id
        }
    })
}

// 商家入驻申请
export const applyShop = (data) => {
    return request({
        url: '/shop/jiang/apply',
        method: 'post',
        data
    })
}


